package com.example.administrator.weather;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mob.tools.utils.Hashon;

import java.util.ArrayList;
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Administrator on 2016/9/4.
 */
public class IPAddressModle {
    private String path = "http://pv.sohu.com/cityjson";
    private List<String> ipList = new ArrayList<>();

    public List<String> getIPAddress() {
        try {
            OkHttpClient httpClient = new OkHttpClient();
            Request request = new Request.Builder().url(path).get().build();
            Response response = httpClient.newCall(request).execute();
            String result = response.body().string();
            result = result.replace("var returnCitySN = {", "{").replace("};", "}");
            String ip = (String) (new Hashon().fromJson(result).get("cip"));
            String city = (String) (new Hashon().fromJson(result).get("cname"));
            ipList.add(city);
            ipList.add(ip);

        } catch (Exception e) {
            e.printStackTrace();

        }
        return ipList;
    }
}
